home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFcompare (differences).
- *
- * Version 2.0, 4-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 1-Jun-91, J Love Original version (for CDF V2.1).
- * V1.1 25-Jun-91, J Love CDF_EPOCH added as a data type. Added QOP.
- * Added PageInst.
- * V1.2 6-Aug-91, J Love TRUE/FALSE. Use 'Exit'/'ExitBAD'. Use
- * 'CDFlib'. Display message if no differences
- * found.
- * V1.3 10-Aug-91, J Love Optimized comparison of variable values.
- * V2.0 4-Mar-92, J Love IBM PC & HP port.
- *
- ******************************************************************************/
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- #include "cdfdist.h"
- #include "cdfcmp.h"
-
- /******************************************************************************
- * Global variables.
- ******************************************************************************/
-
- static CDFid id1, id2;
- static long numDims1, numDims2;
- static long dimSizes1[CDF_MAX_DIMS], dimSizes2[CDF_MAX_DIMS];
- static long encoding1, encoding2;
- static long majority1, majority2;
- static long format1, format2;
- static char copyright1[CDF_COPYRIGHT_LEN], copyright2[CDF_COPYRIGHT_LEN];
- static long numVars1, numVars2;
- static long numAttrs1, numAttrs2;
- static long maxRec1, maxRec2;
- static long version1, version2;
- static long release1, release2;
- static long increment1, increment2;
- static long attrScope1, attrScope2;
- static long attrMaxEntry1, attrMaxEntry2;
- static long attrNumEntries1, attrNumEntries2;
- static long varMaxRec1, varMaxRec2;
- static long varDataType1, varDataType2;
- static long varNumElems1, varNumElems2;
- static long varRecVary1, varRecVary2;
- static long varDimVarys1[CDF_MAX_DIMS], varDimVarys2[CDF_MAX_DIMS];
- static long varExtendRecs1, varExtendRecs2;
- static Boolean mLog;
- static Boolean cmpNumbers;
- static Boolean cmpVars;
- static Boolean cmpAttrs;
- static long *attrNumMatches1, *attrNumMatches2;
- static long *varNumMatches1, *varNumMatches2;
- static Boolean diffFound;
-
- /******************************************************************************
- * main (CDFcompare).
- ******************************************************************************/
-
- #if defined(vms)
- main (argc, argv)
- #else
- void main (argc, argv)
- #endif
- int argc;
- char *argv[];
- {
- char CDFspec1[MAX_PATH_LEN + 1], CDFspec2[MAX_PATH_LEN + 1];
- char CDFspec1t[MAX_PATH_LEN + 1], CDFspec2t[MAX_PATH_LEN + 1];
- char **dirs1, **dirs2;
- char **CDFs1, **CDFs2;
- int numCDFs1, numCDFs2;
- char CDFpath1[MAX_PATH_LEN + 1], CDFpath2[MAX_PATH_LEN + 1];
- char dir1[MAX_DIR_LEN + 1], dir2[MAX_DIR_LEN + 1];
- char CDF1[MAX_NAME_LEN + 1], CDF2[MAX_NAME_LEN + 1];
- int i, j;
- Boolean match;
- long count;
- QOP *qop;
- static char *validQuals[] = { "log", "nolog", "attr", "noattr", "var", "novar",
- "number", "nonumber", NULL };
- static int optRequired[] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
- FALSE, FALSE, 0 };
-
- static char *instructions[] = {
- #if defined(vms)
- "Usage: $ CDFCOMPARE [/[no]LOG] [/[no]ATTR] [/[no]VAR] [/[no]NUMBER]",
- " <cdf-spec-1> <cdf-spec-2>",
- #endif
- #if defined(unix)
- "Usage: % cdfcompare [-[no]log] [-[no]attr] [-[no]var] [-[no]number]",
- " <cdf-spec-1> <cdf-spec-2>",
- #endif
- #if defined(__MSDOS__)
- "Usage: > cdfcompare [-[no]log] [-[no]attr] [-[no]var]",
- " [-[no]number]",
- " <cdf-spec-1> <cdf-spec-2>",
- #endif
- "",
- "Purpose: CDFcompare displays the differences in two CDFs. More than",
- " one pair of CDFs may be compared.",
- "",
- "Parameter(s): <cdf-spec-1>",
- " <cdf-spec-2>",
- " The specifications of the CDFs to be compared (do not",
- " enter extensions). These can be either a pathname",
- " specifying a single CDF or a directory/wildcard path",
- " specifying more than one CDF. Wildcards are allowed in",
- " the CDF name but not in the directory path. The available",
- " wildcards are similar to those on the operating system",
- " being used.",
- "",
- " If two directory/wildcard paths are specified, all of the",
- " CDFs with matching names will be compared. If a CDF",
- " pathname and a directory/wildcard path are specified,",
- " the CDF specified will be compared with the CDF in the",
- " directory/wildcard path having the same name. If two CDF",
- " pathnames are specified, the CDFs are compared (this is",
- " the only way to compare two CDFs having different names).",
- "",
- #if defined(vms)
- "Qualifier(s): /[no]LOG",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- "Qualifier(s): -[no]log",
- #endif
- " Specifies whether or not progress of the comparison is",
- " displayed. The default is logging disabled.",
- "",
- #if defined(vms)
- " /[no]ATTR",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -[no]attr",
- #endif
- " Specifies whether or not attributes are to be compared.",
- " The default is to compare attributes.",
- "",
- #if defined(vms)
- " /[no]VAR",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -[no]var",
- #endif
- " Specifies whether or not variables are to be compared.",
- " The default is to compare variables.",
- "",
- #if defined(vms)
- " /[no]NUMBER",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -[no]number",
- #endif
- " Specifies whether or not numbering differences of",
- " attributes and variables should be displayed. The",
- " default is not to display numbering differences.",
- "",
- #if defined(vms)
- "Example(s): $ CDFCOMPARE GISS_WETL GISS_WETLX",
- " $ CDFCOMPARE/LOG/NOATTR/NUMBER GISS_WETL CDF$SMPL:GISS_WETLX",
- " $ CDFCOMPARE/VAR CDF$SMPL:QST* [.TEMP]",
- " $ CDFCOMPARE NCDS$DATA:CAC_SST_BLENDED [-.CAC]",
- #endif
- #if defined(unix)
- "Example(s): % cdfcompare giss_wetl giss_wetlx",
- " % cdfcompare -log -noattr -number giss_wetl ../../giss_wetlx",
- " % cdfcompare -var '${CDF$SMPL}/QST*' temp",
- " % cdfcompare ~ncds/cac_sst_blended ../cac",
- #endif
- #if defined(__MSDOS__)
- "Example(s): > cdfcompare gisswetl gwetlx",
- " > cdfcompare -log -noattr -number gisswetl ..\\..\\gwetlx",
- " > cdfcompare -var c:\\cdf\\samples\\QST* temp",
- " > cdfcompare b:\\ncds\\cac_sst ..\\cac",
- #endif
- NULL };
-
- /******************************************************************************
- * Get qualifiers/options/parameters.
- ******************************************************************************/
-
- switch (argc == 1) {
- case 1:
- PageInst (instructions);
- Exit;
- default:
- qop = Qop (argc, argv, validQuals, optRequired);
- if (qop == NULL) ExitBAD;
-
- switch (qop->Nparms) {
- case 0:
- case 1:
- printf ("Missing parameter(s).\n");
- ExitBAD;
- case 2:
- strcpy (CDFspec1, qop->parms[0]);
- strcpy (CDFspec2, qop->parms[1]);
- #if defined(vms) | defined(__MSDOS__)
- Upcase (CDFspec1);
- Upcase (CDFspec2);
- #endif
- break;
- default:
- printf ("Too many parameters.\n");
- ExitBAD;
- }
-
- count = 0;
- if (qop->qualEntered[0]) count++;
- if (qop->qualEntered[1]) count++;
-
- switch (count) {
- case 0:
- mLog = FALSE;
- break;
- case 1:
- if (qop->qualEntered[0])
- mLog = TRUE;
- else
- mLog = FALSE;
- break;
- case 2:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- break;
- }
-
- count = 0;
- if (qop->qualEntered[2]) count++;
- if (qop->qualEntered[3]) count++;
-
- switch (count) {
- case 0:
- cmpAttrs = TRUE;
- break;
- case 1:
- if (qop->qualEntered[2])
- cmpAttrs = TRUE;
- else
- cmpAttrs = FALSE;
- break;
- case 2:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- break;
- }
-
- count = 0;
- if (qop->qualEntered[4]) count++;
- if (qop->qualEntered[5]) count++;
-
- switch (count) {
- case 0:
- cmpVars = TRUE;
- break;
- case 1:
- if (qop->qualEntered[4])
- cmpVars = TRUE;
- else
- cmpVars = FALSE;
- break;
- case 2:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- break;
- }
-
- count = 0;
- if (qop->qualEntered[6]) count++;
- if (qop->qualEntered[7]) count++;
-
- switch (count) {
- case 0:
- cmpNumbers = FALSE;
- break;
- case 1:
- if (qop->qualEntered[6])
- cmpNumbers = TRUE;
- else
- cmpNumbers = FALSE;
- break;
- case 2:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- break;
- }
- break;
- }
-
- /******************************************************************************
- * Compare the CDFs.
- ******************************************************************************/
-
- strcpy (CDFspec1t, CDFspec1);
- strcat (CDFspec1t, ".cdf");
-
- strcpy (CDFspec2t, CDFspec2);
- strcat (CDFspec2t, ".cdf");
-
- if ( ! IsReg(CDFspec1t)) {
- if ( ! IsReg(CDFspec2t)) {
- /**************************************************************************
- * Both specifications are directories/wildcards.
- **************************************************************************/
-
- if (IsDir(CDFspec1))
- AppendToDir (CDFspec1, "*.cdf");
- else
- strcat (CDFspec1, ".cdf");
-
- numCDFs1 = DirList (CDFspec1, &dirs1, &CDFs1);
-
- if (IsDir(CDFspec2))
- AppendToDir (CDFspec2, "*.cdf");
- else
- strcat (CDFspec2, ".cdf");
-
- numCDFs2 = DirList (CDFspec2, &dirs2, &CDFs2);
-
- if (numCDFs1 > 0)
- if (numCDFs2 > 0) {
- RemoveExtensions (numCDFs1, CDFs1);
- RemoveExtensions (numCDFs2, CDFs2);
-
- match = FALSE;
-
- for (i = 0; i < numCDFs1; i++)
- for (j = 0; j < numCDFs2; j++) {
- if (strcmp(CDFs1[i],CDFs2[j]) == 0) {
- match = TRUE;
-
- strcpy (CDFpath1, dirs1[i]);
- AppendToDir (CDFpath1, CDFs1[i]);
-
- strcpy (CDFpath2, dirs2[j]);
- AppendToDir (CDFpath2, CDFs2[j]);
-
- CompareCDFs (CDFpath1, CDFpath2);
- CleanupComparison ();
-
- break;
- }
- }
-
- if ( ! match) printf ("No matching CDFs found.\n");
- }
- else
- printf ("No CDFs found for second specification.\n");
- else
- if (numCDFs2 > 0)
- printf ("No CDFs found for first specification.\n");
- else
- printf ("No CDFs for either specification.\n");
- }
- else {
- /**************************************************************************
- * First specification is a directory/wildcard, second is a CDF path.
- **************************************************************************/
-
- if (IsDir(CDFspec1))
- AppendToDir (CDFspec1, "*.cdf");
- else
- strcat (CDFspec1, ".cdf");
-
- numCDFs1 = DirList (CDFspec1, &dirs1, &CDFs1);
-
- if (numCDFs1 > 0) {
- RemoveExtensions (numCDFs1, CDFs1);
- ParsePath (CDFspec2, dir2, CDF2);
-
- match = FALSE;
-
- for (i = 0; i < numCDFs1; i++)
- if (strcmp(CDFs1[i],CDF2) == 0) {
- match = TRUE;
-
- strcpy (CDFpath1, dirs1[i]);
- AppendToDir (CDFpath1, CDFs1[i]);
-
- CompareCDFs (CDFpath1, CDFspec2);
- CleanupComparison ();
-
- break;
- }
-
- if ( ! match) printf ("Matching CDF not found.\n");
- }
- else
- printf ("No CDFs found for specification.\n");
- }
- }
- else {
- if ( ! IsReg(CDFspec2t)) {
- /**************************************************************************
- * First specification is a CDF path, second is a directory/wildcard.
- **************************************************************************/
-
- if (IsDir(CDFspec2))
- AppendToDir (CDFspec2, "*.cdf");
- else
- strcat (CDFspec2, ".cdf");
-
- numCDFs2 = DirList (CDFspec2, &dirs2, &CDFs2);
-
- if (numCDFs2 > 0) {
- RemoveExtensions (numCDFs2, CDFs2);
- ParsePath (CDFspec1, dir1, CDF1);
-
- match = FALSE;
-
- for (i = 0; i < numCDFs2; i++)
- if (strcmp(CDF1,CDFs2[i]) == 0) {
- match = TRUE;
-
- strcpy (CDFpath2, dirs2[i]);
- AppendToDir (CDFpath2, CDFs2[i]);
-
- CompareCDFs (CDFspec1, CDFpath2);
- CleanupComparison ();
-
- break;
- }
-
- if ( ! match) printf ("Matching CDF not found.\n");
- }
- else
- printf ("No CDFs found for specification.\n");
- }
- else {
- /**************************************************************************
- * Both specifications are CDF paths.
- **************************************************************************/
-
- CompareCDFs (CDFspec1, CDFspec2);
- CleanupComparison ();
- }
- }
-
- Exit;
- }
-
- /******************************************************************************
- * CompareCDFs.
- ******************************************************************************/
-
- Boolean CompareCDFs (CDFpath1, CDFpath2)
- char *CDFpath1;
- char *CDFpath2;
- {
- CDFstatus status;
-
- /******************************************************************************
- * Open CDFs.
- ******************************************************************************/
-
- printf ("Comparing \"%s\" with \"%s\"\n", CDFpath1, CDFpath2);
-
- diffFound = FALSE;
-
- status = CDFlib (OPEN_, CDF_, CDFpath1, &id1,
- GET_, CDF_NUMDIMS_, &numDims1,
- CDF_DIMSIZES_, dimSizes1,
- CDF_ENCODING_, &encoding1,
- CDF_MAJORITY_, &majority1,
- CDF_FORMAT_, &format1,
- CDF_COPYRIGHT_, copyright1,
- CDF_NUMVARS_, &numVars1,
- CDF_NUMATTRS_, &numAttrs1,
- CDF_MAXREC_, &maxRec1,
- CDF_VERSION_, &version1,
- CDF_RELEASE_, &release1,
- CDF_INCREMENT_, &increment1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (OPEN_, CDF_, CDFpath2, &id2,
- GET_, CDF_NUMDIMS_, &numDims2,
- CDF_DIMSIZES_, dimSizes2,
- CDF_ENCODING_, &encoding2,
- CDF_MAJORITY_, &majority2,
- CDF_FORMAT_, &format2,
- CDF_COPYRIGHT_, copyright2,
- CDF_NUMVARS_, &numVars2,
- CDF_NUMATTRS_, &numAttrs2,
- CDF_MAXREC_, &maxRec2,
- CDF_VERSION_, &version2,
- CDF_RELEASE_, &release2,
- CDF_INCREMENT_, &increment2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- if (! AttrNumberMatches()) return FALSE;
- if (! VarNumberMatches()) return FALSE;
-
- /******************************************************************************
- * Compare CDFs.
- ******************************************************************************/
-
- if (! CompareGeneral()) return FALSE;
- if (! CompareAttributes()) return FALSE;
- if (! CompareVariables()) return FALSE;
-
- /******************************************************************************
- * Close CDFs.
- ******************************************************************************/
-
- status = CDFclose (id1);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFclose (id2);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- /******************************************************************************
- * If no differences, display message.
- ******************************************************************************/
-
- if ( (! diffFound) && mLog) printf (" No differences detected.\n");
-
- return TRUE; /* Successful comparison. */
- }
-
- /******************************************************************************
- * CompareGeneral.
- ******************************************************************************/
-
- Boolean CompareGeneral ()
- {
- int i, j;
-
- if (numDims1 != numDims2) {
- diffFound = TRUE;
- printf (" Different number of dimensions (%ld vs. %ld)\n",
- numDims1, numDims2);
- cmpVars = FALSE;
- }
- else {
- if (numDims1 > 0)
- for (i = 0; i < numDims1; i++)
- if (dimSizes1[i] != dimSizes2[i]) {
- diffFound = TRUE;
- printf (" Different dimension sizes (");
- for (j = 0; j < numDims1; j++) printf ("%ld ", dimSizes1[j]);
- printf ("vs.");
- for (j = 0; j < numDims2; j++) printf (" %ld", dimSizes2[j]);
- printf (")\n");
- cmpVars = FALSE;
- break;
- }
- }
-
- if (encoding1 != encoding2) {
- diffFound = TRUE;
- printf (" Different encodings (%s vs. %s)\n",
- EncodingToken(encoding1), EncodingToken(encoding2));
- }
-
- if (majority1 != majority2) {
- diffFound = TRUE;
- printf (" Different majorities (%s vs. %s)\n",
- MajorityToken(majority1), MajorityToken(majority2));
- }
-
- if (format1 != format2) {
- diffFound = TRUE;
- printf (" Different formats (%s vs. %s)\n",
- FormatToken(format1), FormatToken(format2));
- }
-
- if (numVars1 != numVars2) {
- diffFound = TRUE;
- printf (" Different number of variables (%ld vs. %ld)\n",
- numVars1, numVars2);
- }
-
- if (numAttrs1 != numAttrs2) {
- diffFound = TRUE;
- printf (" Different number of attributes (%ld vs. %ld)\n",
- numAttrs1, numAttrs2);
- }
-
- if (maxRec1 != maxRec2) {
- diffFound = TRUE;
- printf (" Different maximum record (%ld vs. %ld)\n",
- maxRec1 + 1, maxRec2 + 1);
- }
-
- if (version1 != version2 || release1 != release2 || increment1 != increment2) {
- diffFound = TRUE;
- printf (" Different creation libraries (V%ld.%ld.%ld vs. V%ld.%ld.%ld)\n",
- version1, release1, increment1, version2, release2, increment2);
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- * AttrNumberMatches. Determine attribute number matches.
- ******************************************************************************/
-
- Boolean AttrNumberMatches ()
- {
- CDFstatus status;
- long attrN1, attrN2;
- char attrName[CDF_ATTR_NAME_LEN+1];
-
- if (numAttrs1 > 0) {
- MALLOC (attrNumMatches1, numAttrs1 * sizeof(long));
- }
- else
- attrNumMatches1 = (long *) NULL;
-
- for (attrN1 = 0; attrN1 < numAttrs1; attrN1++) {
- status = CDFlib (SELECT_, CDF_, id1,
- ATTR_, attrN1,
- GET_, ATTR_NAME_, attrName,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- GET_, ATTR_NUMBER_, attrName, &attrN2,
- NULL_);
- if (status == NO_SUCH_ATTR)
- attrNumMatches1[attrN1] = -1;
- else {
- if (! StatusHandler("CDF2",status)) return FALSE;
- attrNumMatches1[attrN1] = attrN2;
- }
- }
-
- if (numAttrs2 > 0) {
- MALLOC (attrNumMatches2, numAttrs2 * sizeof(long));
- }
- else
- attrNumMatches2 = (long *) NULL;
-
- for (attrN2 = 0; attrN2 < numAttrs2; attrN2++) {
- status = CDFlib (SELECT_, CDF_, id2,
- ATTR_, attrN2,
- GET_, ATTR_NAME_, attrName,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id1,
- GET_, ATTR_NUMBER_, attrName, &attrN1,
- NULL_);
- if (status == NO_SUCH_ATTR)
- attrNumMatches2[attrN2] = -1;
- else {
- if (! StatusHandler("CDF1",status)) return FALSE;
- attrNumMatches2[attrN2] = attrN1;
- }
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- * VarNumberMatches. Determine variable number matches.
- ******************************************************************************/
-
- Boolean VarNumberMatches ()
- {
- CDFstatus status;
- long varN1, varN2;
- char varName[CDF_VAR_NAME_LEN+1];
-
- if (numVars1 > 0) {
- MALLOC (varNumMatches1, numVars1 * sizeof(long));
- }
- else
- varNumMatches1 = (long *) NULL;
-
- for (varN1 = 0; varN1 < numVars1; varN1++) {
- status = CDFlib (SELECT_, CDF_, id1,
- VAR_, varN1,
- GET_, VAR_NAME_, varName,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- GET_, VAR_NUMBER_, varName, &varN2,
- NULL_);
- if (status == NO_SUCH_VAR)
- varNumMatches1[varN1] = -1;
- else {
- if (! StatusHandler("CDF2",status)) return FALSE;
- varNumMatches1[varN1] = varN2;
- }
- }
-
- if (numVars2 > 0) {
- MALLOC (varNumMatches2, numVars2 * sizeof(long));
- }
- else
- varNumMatches2 = (long *) NULL;
-
- for (varN2 = 0; varN2 < numVars2; varN2++) {
- status = CDFlib (SELECT_, CDF_, id2,
- VAR_, varN2,
- GET_, VAR_NAME_, varName,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id1,
- GET_, VAR_NUMBER_, varName, &varN1,
- NULL_);
- if (status == NO_SUCH_VAR)
- varNumMatches2[varN2] = -1;
- else {
- if (! StatusHandler("CDF1",status)) return FALSE;
- varNumMatches2[varN2] = varN1;
- }
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- * CompareAttributes.
- ******************************************************************************/
-
- Boolean CompareAttributes ()
- {
- CDFstatus status;
- long attrN1, attrN2;
- char attrName[CDF_ATTR_NAME_LEN+1];
- Boolean cmpAttr;
-
- if (cmpAttrs) {
- for (attrN1 = 0; attrN1 < numAttrs1; attrN1++) {
- if (attrNumMatches1[attrN1] == -1) {
- status = CDFlib (SELECT_, CDF_, id1,
- ATTR_, attrN1,
- GET_, ATTR_NAME_, attrName,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
- diffFound = TRUE;
- printf (" Attribute %s does not exist in CDF2\n", attrName);
- }
- else {
- status = CDFlib (SELECT_, CDF_, id1,
- ATTR_, attrN1,
- GET_, ATTR_NAME_, attrName,
- ATTR_SCOPE_, &attrScope1,
- ATTR_MAXENTRY_, &attrMaxEntry1,
- ATTR_NUMENTRIES_, &attrNumEntries1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- ATTR_, attrNumMatches1[attrN1],
- GET_, ATTR_SCOPE_, &attrScope2,
- ATTR_MAXENTRY_, &attrMaxEntry2,
- ATTR_NUMENTRIES_, &attrNumEntries2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- if (mLog) printf (" Comparing attribute \"%s\"\n", attrName);
-
- cmpAttr = TRUE;
-
- if (cmpNumbers)
- if (attrNumMatches1[attrN1] != attrN1) {
- diffFound = TRUE;
- printf (" Different numbers for attribute %s (%ld vs. %ld)\n",
- attrName, attrN1 + 1, attrNumMatches1[attrN1] + 1);
- }
-
- if (attrScope1 != attrScope2) {
- diffFound = TRUE;
- printf (" Different scopes for attribute %s (%s vs. %s)\n",
- attrName, ScopeToken(attrScope1), ScopeToken(attrScope2));
- cmpAttr = FALSE;
- }
-
- if (attrMaxEntry1 != attrMaxEntry2) {
- diffFound = TRUE;
- printf
- (" Different maximum entry for attribute %s (%ld vs. %ld)\n",
- attrName, attrMaxEntry1 + 1, attrMaxEntry2 + 1);
- }
-
- if (attrNumEntries1 != attrNumEntries2) {
- diffFound = TRUE;
- printf (" Different num. entries for attribute %s (%ld vs. %ld)\n",
- attrName, attrNumEntries1, attrNumEntries2);
- }
-
- if (cmpAttr) CompareAttributeEntries (attrN1, attrNumMatches1[attrN1],
- attrName);
- }
- }
-
- for (attrN2 = 0; attrN2 < numAttrs2; attrN2++)
- if (attrNumMatches2[attrN2] == -1) {
- status = CDFlib (SELECT_, CDF_, id2,
- ATTR_, attrN2,
- GET_, ATTR_NAME_, attrName,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
- diffFound = TRUE;
- printf (" Attribute %s does not exist in CDF1\n", attrName);
- }
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- * CompareAttributeEntries.
- ******************************************************************************/
-
- Boolean CompareAttributeEntries (attrN1, attrN2, attrName)
- long attrN1;
- long attrN2;
- char *attrName;
- {
- CDFstatus status;
- char varName[CDF_VAR_NAME_LEN+1];
- long entryN;
- long entryN1;
- long entryN2;
-
- status = CDFlib (SELECT_, CDF_, id1,
- ATTR_, attrN1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- ATTR_, attrN2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- if (attrScope1 == GLOBAL_SCOPE || attrScope1 == GLOBAL_SCOPE_ASSUMED) {
- for (entryN = 0; entryN <= Maximum(attrMaxEntry1,attrMaxEntry2); entryN++)
- CompareEntry (attrName, entryN, entryN, NULL);
- }
- else {
- for (entryN1 = 0; entryN1 <= attrMaxEntry1; entryN1++)
- if (entryN1 < numVars1)
- if (varNumMatches1[entryN1] == -1) {
- diffFound = TRUE;
- printf (" No corresponding variable in CDF2 for entry number");
- printf (" %ld of attribute %s in CDF1\n", entryN1 + 1, attrName);
- }
- else {
- status = CDFlib (SELECT_, CDF_, id1,
- VAR_, entryN1,
- GET_, VAR_NAME_, varName,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
- CompareEntry (attrName, entryN1, varNumMatches1[entryN1], varName);
- }
- else
- CompareEntry (attrName, entryN1, entryN1, NULL); /* assume GLOBAL? */
-
- for (entryN2 = 0; entryN2 <= attrMaxEntry2; entryN2++)
- if (entryN2 < numVars2) {
- if (varNumMatches2[entryN2] == -1) {
- diffFound = TRUE;
- printf (" No corresponding variable in CDF1 for entry number");
- printf (" %ld of attribute %s in CDF2\n", entryN2 + 1, attrName);
- }
- }
- else
- CompareEntry (attrName, entryN2, entryN2, NULL); /* assume GLOBAL? */
- }
- return TRUE;
- }
-
- /******************************************************************************
- * CompareEntry. It is assumed that the attribute has already been selected
- * in the two CDFs.
- ******************************************************************************/
-
- Boolean CompareEntry (attrName, entryN1, entryN2, varName)
- char *attrName;
- long entryN1;
- long entryN2;
- char *varName; /* if == NULL, then GLOBAL scope attribute and the
- entry numbers are assumed to be the same,
- if != NULL, then VARIABLE scope attribute and
- this is the associated variable for these entries */
- {
- CDFstatus status;
- CDFstatus status1;
- CDFstatus status2;
- long entryDataType1, entryDataType2;
- long entryNumElems1, entryNumElems2;
- void *entryValue1, *entryValue2;
- char varNameField[CDF_VAR_NAME_LEN+13];
- char entryNumField[12];
- long Nbytes;
-
- if (varName == NULL) {
- varNameField[0] = '\0';
- sprintf (entryNumField, "%ld", entryN1);
- }
- else {
- strcpy (varNameField, " (variable ");
- strcat (varNameField, varName);
- strcat (varNameField, ")");
- if (entryN1 == entryN2)
- sprintf (entryNumField, "%ld", entryN1);
- else
- sprintf (entryNumField, "%ld/%ld", entryN1, entryN2);
- }
-
- status1 = CDFlib (SELECT_, CDF_, id1,
- ENTRY_, entryN1,
- GET_, ENTRY_DATATYPE_, &entryDataType1,
- ENTRY_NUMELEMS_, &entryNumElems1,
- NULL_);
- status2 = CDFlib (SELECT_, CDF_, id2,
- ENTRY_, entryN2,
- GET_, ENTRY_DATATYPE_, &entryDataType2,
- ENTRY_NUMELEMS_, &entryNumElems2,
- NULL_);
-
- if (status1 == NO_SUCH_ENTRY && status2 == NO_SUCH_ENTRY) return TRUE;
-
- if (status1 == NO_SUCH_ENTRY) {
- diffFound = TRUE;
- printf (" No entry number %ld%s for attribute %s in CDF1\n",
- entryN1 + 1, varNameField, attrName);
- return TRUE;
- }
-
- if (status2 == NO_SUCH_ENTRY) {
- diffFound = TRUE;
- printf (" No entry number %ld%s for attribute %s in CDF2\n",
- entryN2 + 1, varNameField, attrName);
- return TRUE;
- }
-
- if (! StatusHandler("CDF1",status1)) return FALSE;
- if (! StatusHandler("CDF2",status2)) return FALSE;
-
- if (entryDataType1 != entryDataType2) {
- diffFound = TRUE;
- printf (" Different data types for entry number %s%s of attribute %s ",
- entryNumField, varNameField, attrName);
- printf ("(%s vs. %s)\n",
- DataTypeToken(entryDataType1), DataTypeToken(entryDataType2));
- /* DON'T RETURN IF THIS DIFFERENCE FOUND */
- }
-
- if ( ! EquivalentDataTypes(entryDataType1,entryDataType2)) {
- diffFound = TRUE;
- printf
- (" Non-equivalent data types for entry number %s%s of attribute %s ",
- entryNumField, varNameField, attrName);
- printf ("(%s vs. %s)\n",
- DataTypeToken(entryDataType1), DataTypeToken(entryDataType2));
- return TRUE;
- }
-
- if (entryNumElems1 != entryNumElems2) {
- diffFound = TRUE;
- printf (" Different number of elements for entry number %s",
- entryNumField);
- printf ("%s of attribute %s (%ld vs. %ld)\n", varNameField,
- attrName, entryNumElems1, entryNumElems2);
- return TRUE;
- }
-
- Nbytes = entryNumElems1 * DataTypeSize(entryDataType1);
-
- MALLOC (entryValue1, Nbytes);
- MALLOC (entryValue2, Nbytes);
-
- status = CDFlib (SELECT_, CDF_, id1,
- GET_, ENTRY_DATA_, entryValue1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- GET_, ENTRY_DATA_, entryValue2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- if (memcmp(entryValue1,entryValue2,Nbytes) != 0) {
- diffFound = TRUE;
- printf (" Different values for entry number %s%s of attribute %s\n",
- entryNumField, varNameField, attrName);
- }
-
- free (entryValue1);
- free (entryValue2);
-
- return TRUE;
- }
-
- /******************************************************************************
- * CompareVariables.
- ******************************************************************************/
-
- Boolean CompareVariables ()
- {
- CDFstatus status;
- long varN1, varN2;
- char varName[CDF_VAR_NAME_LEN + 1];
- Boolean cmpVar;
- int i, j;
-
- if (cmpVars) {
- for (varN1 = 0; varN1 < numVars1; varN1++) {
- if (varNumMatches1[varN1] == -1) {
- status = CDFlib (SELECT_, CDF_, id1,
- VAR_, varN1,
- GET_, VAR_NAME_, varName,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
- diffFound = TRUE;
- printf (" Variable %s does not exist in CDF2\n", varName);
- }
- else {
- status = CDFlib (SELECT_, CDF_, id1,
- VAR_, varN1,
- GET_, VAR_NAME_, varName,
- VAR_DATATYPE_, &varDataType1,
- VAR_NUMELEMS_, &varNumElems1,
- VAR_RECVARY_, &varRecVary1,
- VAR_DIMVARYS_, varDimVarys1,
- VAR_MAXREC_, &varMaxRec1,
- VAR_EXTENDRECS_, &varExtendRecs1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- VAR_, varNumMatches1[varN1],
- GET_, VAR_DATATYPE_, &varDataType2,
- VAR_NUMELEMS_, &varNumElems2,
- VAR_RECVARY_, &varRecVary2,
- VAR_DIMVARYS_, varDimVarys2,
- VAR_MAXREC_, &varMaxRec2,
- VAR_EXTENDRECS_, &varExtendRecs2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- if (mLog) printf (" Comparing variable \"%s\"\n", varName);
-
- cmpVar = TRUE;
-
- if (cmpNumbers)
- if (varNumMatches1[varN1] != varN1) {
- diffFound = TRUE;
- printf (" Different numbers for variable %s (%ld vs. %ld)\n",
- varName, varN1 + 1, varNumMatches1[varN1] + 1);
- }
-
- if (varDataType1 != varDataType2) {
- diffFound = TRUE;
- printf (" Different data types for variable %s (%s vs. %s)\n",
- varName, DataTypeToken(varDataType1),
- DataTypeToken(varDataType2));
- /* STILL MIGHT BE ABLE TO COMPARE VARIABLES. */
- }
-
- if ( ! EquivalentDataTypes(varDataType1,varDataType2)) {
- diffFound = TRUE;
- printf (" Non-equivalent data types for variable %s (%s vs. %s)\n",
- varName, DataTypeToken(varDataType1),
- DataTypeToken(varDataType2));
- cmpVar = FALSE;
- }
-
- if (varNumElems1 != varNumElems2) {
- diffFound = TRUE;
- printf
- (" Different number of elements for variable %s (%ld vs. %ld)\n",
- varName, varNumElems1, varNumElems2);
- cmpVar = FALSE;
- }
-
- if (varRecVary1 != varRecVary2) {
- diffFound = TRUE;
- printf
- (" Different record variances for variable %s (%s vs. %s)\n",
- varName, VarianceToken(varRecVary1), VarianceToken(varRecVary2));
- }
-
- for (i = 0; i < numDims1; i++)
- if (varDimVarys1[i] != varDimVarys2[i]) {
- diffFound = TRUE;
- printf (" Different dimension variances for variable %s (",
- varName);
- for (j = 0; j < numDims1; j++)
- printf ("%ld ", VarianceToken(varDimVarys1[j]));
- printf ("vs.");
- for (j = 0; j < numDims2; j++)
- printf (" %ld", VarianceToken(varDimVarys2[j]));
- printf (")\n");
- break;
- }
-
- if (varMaxRec1 != varMaxRec2) {
- diffFound = TRUE;
- printf(" Different maximum record for variable %s (%ld vs. %ld)\n",
- varName, varMaxRec1 + 1, varMaxRec2 + 1);
- }
-
- if (varExtendRecs1 != varExtendRecs2) {
- diffFound = TRUE;
- printf(" Different extend records for variable %s (%ld vs. %ld)\n",
- varName, varExtendRecs1, varExtendRecs2);
- }
-
- if (cmpVar) CompareVariableValues (varN1, varNumMatches1[varN1],
- varName);
- }
- }
-
- for (varN2 = 0; varN2 < numVars2; varN2++)
- if (varNumMatches2[varN2] == -1) {
- status = CDFlib (SELECT_, CDF_, id2,
- VAR_, varN2,
- GET_, VAR_NAME_, varName,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
- diffFound = TRUE;
- printf (" Varibute %s does not exist in CDF1\n", varName);
- }
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- * CompareVariableValues.
- ******************************************************************************/
-
- Boolean CompareVariableValues (varN1, varN2, varName)
- long varN1;
- long varN2;
- char *varName;
- {
- void *buffer1;
- void *buffer2;
- void *bufferX; /* Buffer with majority switched. */
- void *bufferZ; /* Buffer with which to compare. */
- void *fillValue1;
- void *fillValue2;
- CDFstatus status, status1, status2;
- long NrecBytes, NvalueBytes, NrecValues;
- long dimN, valueN, recN;
- long maxRec;
- enum flipENUM {noFLIP_,ROWtoCOL_,COLtoROW_} flip;
- enum accTypeENUM {HYP,SEQ,SIN} accType;
- static long HYPindices[CDF_MAX_DIMS] = {0,0,0,0,0,0,0,0,0,0};
- static long HYPcounts[CDF_MAX_DIMS];
- static long HYPintervals[CDF_MAX_DIMS] = {1,1,1,1,1,1,1,1,1,1};
- static long SEQindices[CDF_MAX_DIMS] = {0,0,0,0,0,0,0,0,0,0};
- static long SINcounts[CDF_MAX_DIMS];
- long indices[CDF_MAX_DIMS];
-
- /******************************************************************************
- * Select variables.
- ******************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, id1,
- VAR_, varN1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- VAR_, varN2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- /******************************************************************************
- * Compare fill values.
- ******************************************************************************/
-
- NvalueBytes = varNumElems1 * DataTypeSize(varDataType1);
-
- MALLOC (fillValue1, NvalueBytes);
- MALLOC (fillValue2, NvalueBytes);
-
- status1 = CDFlib (SELECT_, CDF_, id1,
- GET_, VAR_FILLVALUE_, fillValue1,
- NULL_);
- status2 = CDFlib (SELECT_, CDF_, id2,
- GET_, VAR_FILLVALUE_, fillValue2,
- NULL_);
-
- if (status1 != NO_FILLVALUE_SPECIFIED) {
- if (! StatusHandler("CDF1",status1)) return FALSE;
- if (status2 != NO_FILLVALUE_SPECIFIED) {
- if (! StatusHandler("CDF2",status2)) return FALSE;
- if (memcmp(fillValue1,fillValue2,NvalueBytes) != 0) {
- diffFound = TRUE;
- printf (" Different fill values for variable %s\n", varName);
- }
- }
- else {
- diffFound = TRUE;
- printf (" No fill value for variable %s in CDF2\n", varName);
- }
- }
- else {
- if (status2 != NO_FILLVALUE_SPECIFIED) {
- if (! StatusHandler("CDF2",status2)) return FALSE;
- diffFound = TRUE;
- printf (" No fill value for variable %s in CDF1\n", varName);
- }
- }
-
- free (fillValue1);
- free (fillValue2);
-
- /******************************************************************************
- * Calculate number of values/bytes per record.
- ******************************************************************************/
-
- NrecValues = 1;
-
- if (numDims1 > 0)
- for (dimN = 0; dimN < numDims1; dimN++)
- if (varDimVarys1[dimN] ||
- varDimVarys2[dimN]) NrecValues *= dimSizes1[dimN];
-
- NrecBytes = NrecValues * NvalueBytes;
-
- /******************************************************************************
- * Determine type of access.
- ******************************************************************************/
-
- switch (numDims1) {
- case 0:
- if (varRecVary1 == varRecVary2 && varMaxRec1 == varMaxRec2)
- accType = SEQ;
- else
- accType = SIN;
- MALLOC (buffer1, NvalueBytes);
- MALLOC (buffer2, NvalueBytes);
-
- break;
-
- case 1:
- #if defined(__MSDOS__)
- if (NrecBytes > (long) 65535) {
- if (SameVarys(numDims1,varRecVary1,varRecVary2,
- varDimVarys1,varDimVarys2) && varMaxRec1 == varMaxRec2)
- accType = SEQ;
- else
- accType = SIN;
- MALLOC (buffer1, NvalueBytes);
- MALLOC (buffer2, NvalueBytes);
- }
- else {
- #endif
- buffer1 = (void *) malloc (NrecBytes);
- buffer2 = (void *) malloc (NrecBytes);
-
- if (buffer1 == NULL || buffer2 == NULL) {
- if (buffer1 != NULL) free (buffer1);
- if (buffer2 != NULL) free (buffer2);
-
- if (SameVarys(numDims1,varRecVary1,varRecVary2,
- varDimVarys1,varDimVarys2) && varMaxRec1 == varMaxRec2)
- accType = SEQ;
- else
- accType = SIN;
-
- MALLOC (buffer1, NvalueBytes);
- MALLOC (buffer2, NvalueBytes);
- }
- else {
- accType = HYP;
- flip = noFLIP_; /* Majority doesn't matter if 1-dimensional. */
- }
- #if defined(__MSDOS__)
- }
- #endif
-
- break;
-
- default:
- #if defined(__MSDOS__)
- if (NrecBytes > (long) 65535) {
- if (SameVarys(numDims1,varRecVary1,varRecVary2,
- varDimVarys1,varDimVarys2) && majority1 == majority2 &&
- varMaxRec1 == varMaxRec2)
- accType = SEQ;
- else
- accType = SIN;
- MALLOC (buffer1, NvalueBytes);
- MALLOC (buffer2, NvalueBytes);
- }
- else {
- #endif
- buffer1 = (void *) malloc (NrecBytes);
- buffer2 = (void *) malloc (NrecBytes);
- if (majority1 != majority2) bufferX = (void *) malloc (NrecBytes);
-
- if (buffer1 == NULL || buffer2 == NULL ||
- (majority1 != majority2 && bufferX == NULL)) {
- if (buffer1 != NULL) free (buffer1);
- if (buffer2 != NULL) free (buffer2);
- if (majority1 != majority2 && bufferX != NULL) free (bufferX);
-
- if (SameVarys(numDims1,varRecVary1,varRecVary2,
- varDimVarys1,varDimVarys2) &&
- majority1 == majority2 && varMaxRec1 == varMaxRec2)
- accType = SEQ;
- else
- accType = SIN;
- MALLOC (buffer1, NvalueBytes);
- MALLOC (buffer2, NvalueBytes);
- }
- else {
- accType = HYP;
- if (majority1 == majority2)
- flip = noFLIP_;
- else
- if (majority1 == ROW_MAJOR)
- flip = ROWtoCOL_;
- else
- flip = COLtoROW_;
- }
- #if defined(__MSDOS__)
- }
- #endif
-
- break;
- }
-
- /******************************************************************************
- * Compare variable values.
- ******************************************************************************/
-
- switch (accType) {
- case HYP:
- /***********************************************************************
- * Use hyper reads/writes.
- ***********************************************************************/
-
- if (mLog) printf (" (comparing values with hyper reads/writes)\n");
-
- for (dimN = 0; dimN < numDims1; dimN++)
- if (varDimVarys1[dimN] || varDimVarys2[dimN])
- HYPcounts[dimN] = dimSizes1[dimN];
- else
- HYPcounts[dimN] = 1;
-
- status = CDFlib (SELECT_, CDF_, id1,
- CDF_RECCOUNT_, (long) 1,
- CDF_RECINTERVAL_, (long) 1,
- CDF_DIMINDICES_, HYPindices,
- CDF_DIMCOUNTS_, HYPcounts,
- CDF_DIMINTERVALS_, HYPintervals,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- CDF_RECCOUNT_, (long) 1,
- CDF_RECINTERVAL_, (long) 1,
- CDF_DIMINDICES_, HYPindices,
- CDF_DIMCOUNTS_, HYPcounts,
- CDF_DIMINTERVALS_, HYPintervals,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- maxRec = Maximum (varMaxRec1, varMaxRec2);
-
- for (recN = 0; recN <= maxRec; recN++) {
- status = CDFlib (SELECT_, CDF_, id1,
- CDF_RECNUMBER_, recN,
- GET_, VAR_HYPERDATA_, buffer1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- CDF_RECNUMBER_, recN,
- GET_, VAR_HYPERDATA_, buffer2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- switch (flip) {
- case ROWtoCOL_:
- ROWtoCOL (buffer1, bufferX, numDims1, HYPcounts, NvalueBytes);
- bufferZ = bufferX;
- break;
- case COLtoROW_:
- COLtoROW (buffer1, bufferX, numDims1, HYPcounts, NvalueBytes);
- bufferZ = bufferX;
- break;
- case noFLIP_:
- bufferZ = buffer1;
- break;
- }
-
- if (memcmp(bufferZ,buffer2,NrecBytes) != 0) {
- printf (" Difference in record %ld for variable %s",
- recN + 1, varName);
- printf (" (next...)\n");
- break; /* Stop comparing records. */
- }
- }
-
- free (buffer1);
- free (buffer2);
- if (majority1 != majority2) free (bufferX);
-
- break;
-
- case SEQ:
- /***********************************************************************
- * Use sequential reads/writes. Sequential access should only be used
- * if the variables are physically identical.
- ***********************************************************************/
-
- if (mLog) printf (" (comparing values with sequential reads/writes)\n");
-
- status = CDFlib (SELECT_, CDF_, id1,
- VAR_SEQPOS_, (long) 0, SEQindices,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- VAR_SEQPOS_, (long) 0, SEQindices,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- status1 = CDFlib (SELECT_, CDF_, id1,
- GET_, VAR_SEQDATA_, buffer1,
- NULL_);
- status2 = CDFlib (SELECT_, CDF_, id2,
- GET_, VAR_SEQDATA_, buffer2,
- NULL_);
- while (status1 >= CDF_OK && status2 >= CDF_OK) {
- if (memcmp(buffer1,buffer2,NvalueBytes) != 0) {
- printf (" Difference found for variable %s", varName);
- printf (" (next...)\n");
- free (buffer1); /* Stop comparing records. */
- free (buffer2);
- return TRUE;
- }
-
- status1 = CDFlib (SELECT_, CDF_, id1,
- GET_, VAR_SEQDATA_, buffer1,
- NULL_);
- status2 = CDFlib (SELECT_, CDF_, id2,
- GET_, VAR_SEQDATA_, buffer2,
- NULL_);
- }
- if (status1 != END_OF_VAR)
- if (! StatusHandler("CDF1",status)) return FALSE;
- if (status2 != END_OF_VAR)
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- free (buffer1);
- free (buffer2);
-
- break;
-
- case SIN:
- /***********************************************************************
- * Use Single reads/writes. Note that 0-dimensional CDFs are possible
- * here. (If so, anything involving dimension indices, counts, etc. does
- * not necessarily apply. Since a 0-dimensional CDF here is unlikely,
- * checking for that case is not done to save the overhead for multi-
- * dimensional CDFs).
- ***********************************************************************/
-
- if (mLog) printf (" (comparing values with single reads/writes)\n");
-
- for (dimN = 0; dimN < numDims1; dimN++)
- if (varDimVarys1[dimN] || varDimVarys2[dimN])
- SINcounts[dimN] = dimSizes1[dimN];
- else
- SINcounts[dimN] = 1;
-
- maxRec = Maximum (varMaxRec1, varMaxRec2);
-
- for (recN = 0; recN <= maxRec; recN++) {
- for (dimN = 0; dimN < numDims1; dimN++) indices[dimN] = 0;
-
- status = CDFlib (SELECT_, CDF_, id1,
- CDF_RECNUMBER_, recN,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- CDF_RECNUMBER_, recN,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- for (valueN = 0; valueN < NrecValues; valueN++) {
- status = CDFlib (SELECT_, CDF_, id1,
- CDF_DIMINDICES_, indices,
- GET_, VAR_DATA_, buffer1,
- NULL_);
- if (! StatusHandler("CDF1",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, id2,
- CDF_DIMINDICES_, indices,
- GET_, VAR_DATA_, buffer2,
- NULL_);
- if (! StatusHandler("CDF2",status)) return FALSE;
-
- if (memcmp(buffer1,buffer2,NvalueBytes) != 0) {
- printf (" Difference in record %ld for variable %s",
- recN + 1, varName);
- printf (" (next...)\n");
- free (buffer1);
- free (buffer2);
- return TRUE;
- }
-
- if (majority1 == ROW_MAJOR) {
- INCRindicesROW (numDims1, SINcounts, indices);
- }
- else {
- INCRindicesCOL (numDims1, SINcounts, indices);
- }
- }
- }
-
- free (buffer1);
- free (buffer2);
-
- break;
- }
-
- return TRUE;
- }
-
- /******************************************************************************
- * CleanupComparison.
- ******************************************************************************/
-
- void CleanupComparison ()
- {
- CDFclose (id1);
- CDFclose (id2);
-
- if (attrNumMatches1 != NULL) free (attrNumMatches1);
- if (attrNumMatches2 != NULL) free (attrNumMatches2);
-
- if (varNumMatches1 != NULL) free (varNumMatches1);
- if (varNumMatches2 != NULL) free (varNumMatches2);
-
- return;
- }
-
-
- /******************************************************************************
- * SameVarys.
- ******************************************************************************/
-
- Boolean SameVarys (numDims, recVary1, recVary2, dimVarys1, dimVarys2)
- long numDims;
- long recVary1;
- long recVary2;
- long dimVarys1[];
- long dimVarys2[];
- {
- int dimNum;
-
- if (recVary1 != recVary2) return FALSE;
-
- for (dimNum = 0; dimNum < numDims; dimNum++)
- if (dimVarys1[dimNum] != dimVarys2[dimNum]) return FALSE;
-
- return TRUE;
- }
-
-
- /******************************************************************************
- * EquivalentDataTypes.
- ******************************************************************************/
-
- Boolean EquivalentDataTypes (dataType1, dataType2)
- long dataType1;
- long dataType2;
- {
- static long realDataType[] = {0,1,2,0,3,0,0,0,0,0,
- 0,4,5,0,6,0,0,0,0,0,
- 0,7,8,0,0,0,0,0,0,0,
- 0,8,0,0,0,0,0,0,0,0,
- 0,1,0,0,7,8,0,0,0,0,
- 0,9,9,0,0,0,0,0,0,0};
- if (realDataType[dataType1] == realDataType[dataType2])
- return TRUE;
- else
- return FALSE;
- }
-
- /******************************************************************************
- * DataTypeSize. Return size (bytes) of a data type.
- ******************************************************************************/
-
- long DataTypeSize(dataType)
- long dataType;
- {
- switch (dataType) {
- case CDF_BYTE: return 1;
- case CDF_INT1: return 1;
- case CDF_INT2: return 2;
- case CDF_INT4: return 4;
- case CDF_UINT1: return 1;
- case CDF_UINT2: return 2;
- case CDF_UINT4: return 4;
- case CDF_REAL4: return 4;
- case CDF_REAL8: return 8;
- case CDF_FLOAT: return 4;
- case CDF_DOUBLE: return 8;
- case CDF_EPOCH: return 8;
- case CDF_CHAR: return 1;
- case CDF_UCHAR: return 1;
- }
- return 0;
- }
-
- /******************************************************************************
- * StatusHandler.
- ******************************************************************************/
-
- Boolean StatusHandler(which, status)
- char *which;
- CDFstatus status;
- {
- char text[CDF_STATUSTEXT_LEN + 1];
-
- if (status == CDF_OK) return TRUE; /* Do nothing. */
-
- CDFlib (SELECT_, CDF_STATUS_, status,
- GET_, STATUS_TEXT_, text,
- NULL_);
-
- if (status < CDF_WARN) {
- printf (" ERROR, %s> %s\n", which, text);
- return FALSE;
- }
- else {
- if (mLog)
- if (status < CDF_OK)
- printf (" WARNING, %s> %s\n", which, text);
- else
- printf (" INFO, %s> %s\n", which, text);
- return TRUE;
- }
- }
-